import { Component } from 'react';
import Taro, { getCurrentInstance } from '@tarojs/taro';
import { View } from '@tarojs/components'
import { getOrderExpress } from '@/api/order'
import './index.scss'

type State = {
  params: object
	list:[]
}
export default class Index extends Component {
  $instance = getCurrentInstance();
  constructor(props) {
    super(props)
    this.state = {
      params:{},
			list:[]
    }
  }
  state: State
  UNSAFE_componentWillMount() { }
  componentDidMount() {
		const { params } = this.$instance.router.params
		let trans = JSON.parse(params)
		Taro.showLoading({
			title: '加载中...',
			mask: true
	})
		this.setState({
			params:trans
		},()=>{
			let {
				expressNumber,
				consigneeMobile
			} = trans
			getOrderExpress({
				no:expressNumber,
				mobile:consigneeMobile

		}).then(res => {
			let data = res.data.data.list || []
			let list = data.reverse()
			console.log('res',res)
			this.setState({
				list
			})
		})
		})

	}
  UNSAFE_componentWillReceiveProps(nextProps) {}
  changeRefundReason(value) {
    this.setState({
      refundReason: value
    })
  }
  changeLinkMan(value) {
    this.setState({
      linkman: value
    })
  }
  changeMobile(value) {
    this.setState({
      mobile: value
    })
  }

  render() {
		let {params,list} = this.state
		// let {expressNumber,consigneeMobile,consigneeAddress,expectDateLabel}

    return <View className='logistics'>
			<View className='info'>
				<View className='info-item'>
					<View className='info-key'>订单编号</View>
					<View className='info-val'>{params && params.expressNumber || '--'}</View>
				</View>
				<View className='info-item'>
					<View className='info-key'>预计送达</View>
					<View className='info-val'>{params && params.expectDateLabel || '--'}</View>
				</View>
			</View>
			<View className='info'>
				<View className='info-item'>
					<View className='info-key'>收获地址</View>
					<View className='info-val'>{params && params.consigneeAddress || '--'}</View>
				</View>

				<View className='logistics-box'>
					{
						list && list.length > 0 && list.map(item=>{
							return  	<View className='box-item'>
							<View className='box-item__f'></View>
							<View className='box-item__dot'></View>
							<View className='box-item__con'>{item.content}
							<View className='time'>{item.time}</View>
							</View>
						</View>
						})
					}
				</View>

			</View>

    </View>
  }
}
